<?php

namespace addons\third\library;

use fast\Http;

class Tiktok
{

    //
    const GET_ACCESS_TOKEN_URL = 'https://developer.toutiao.com/api/apps/v2/token';

    //
    const GET_CODE2_SESSION = 'https://developer.toutiao.com/api/apps/v2/jscode2session';

    protected $code = null;

    protected $config = null;

    protected $anonymous_code = null;

    public function __construct($code, $anonymous_code)
    {
        $this->code = $code;
        $this->anonymous_code = $anonymous_code;
        $this->config = get_addon_config('third')['tiktok'];
        $this->getCode2Session();
    }

    /**
     * 登录
     * @author: wooooh
     * @dateTime: 2022/5/13 15:30
     */
    public function login()
    {

    }

    /**
     * 获取token
     * @author: wooooh
     * @dateTime: 2022/5/13 15:31
     */
    public function getAccessToken()
    {

    }

    /**
     *
     * @author: wooooh
     * @dateTime: 2022/5/13 15:31
     */
    public function getCode2Session()
    {
        $queryparam = [
            'code'           => $this->code,
            'appid'          => $this->config['app_id'],
            'secret'         => $this->config['app_secret'],
            'anonymous_code' => $this->anonymous_code,
        ];
        return Http::post(self::GET_CODE2_SESSION, $queryparam);
    }
}